package manager

import (
	"BlazeRider-backend/app/db"
	"database/sql"
)

// manager/user_mysql_storage.go
type trackMySQLStorage struct {
}

func newTrackMySQLStorage() (*trackMySQLStorage, error) {

	return &trackMySQLStorage{}, nil
}

// 获取用户信息
func (um *trackMySQLStorage) GetUserTrack(RoomId string, userID string, times int) (*TrackInfo, bool) {
	var track TrackInfo
	err := db.GetDB().QueryRow(`
		SELECT live_room_id, user_id, times, track, create_at, update_at
		FROM live_track
		WHERE live_room_id = ? , 
		user_id = ?, 
		times = ?
	`, RoomId,
		userID,
		times).Scan(
		&track.LiveRoomId,
		&track.UserId,
		&track.Times,
		&track.Track,
		&track.CreateAt,
		&track.UpdateAt,
	)

	if err != nil {
		if err == sql.ErrNoRows {
			return nil, false
		}
		// 记录日志
		return nil, false
	}
	return &track, true
}
